import json


def read_line_txt_test():
    try:
        with open('../datafile/abc.txt', encoding='utf-8') as file:
            content = file.readlines(3)
            print("content===", content)  # rstrip()删除字符串末尾的空行

        # 逐行读取数据
        line_list = []
        for line in content:
            # print(line)
            #
            line_list.append(line.strip('\n'))
        print(json.dumps(line_list))
    except Exception as ee:
        print("读写文件异常", ee)
    finally:
        file.close()


if __name__ == '__main__':
    read_line_txt_test()
